<template>
    <view class="model" @click="hideShow" v-if="shows">
        <view class="pupop" @click.stop>
            <view class="title">提示</view>
            <view class="content">
                未授权登录，请点击下方按钮进行授权登录~
            </view>
            <view class="btn">
                <button open-type="getUserInfo" @getuserinfo="bindGetUserInfo">点击授权</button>
            </view>
        </view>
    </view>

</template>

<script>
    export default {
        name: "authorization",
        props:{
            show:{
                required: true,
                type:Boolean
            },
        },
        data(){
            return{
                shows: this.show,
            }
        },
        methods:{
            //授权登录
            async bindGetUserInfo(){
                var _this=this;
                uni.login({
                    success: res =>{
                        let code = res.code;
                        uni.getUserInfo({
                            success: async res => {
                                let params = {
                                    raw_data:res.rawData,
                                    signature:res.signature,
                                    code:code
                                }
                                const result = await _this.$api.wxAppLogin(params);
                                if (result.data.level == 'success'){
                                    uni.setStorageSync('userToken',result.data.data);
                                    const res2=await _this.$api.getUserInfos({user_token:result.data.data});
                                    if(res2.data.level=='success') {
                                        uni.setStorageSync('UserId', res2.data.data.id);
                                        uni.setStorageSync('is_Vip',res2.data.data.user_info.is_member_unit);
                                        uni.setStorageSync('is_unit_auth',res2.data.data.user_info.is_unit_auth);
                                        _this.$parent.getActivityDetail();
                                        _this.shows = false;
                                    }
                                }
                            }
                        })
                    }
                })
            },
            hideShow(){
                this.shows = false
            }
        },
        watch:{
            show(newValue){
                this.shows = newValue;
            },
            shows(newValue,oldValue){
                this.$emit('update:show',newValue);
            }
        }
    }
</script>

<style scoped lang="scss">
    @import '~@/static/scss/mixin.scss';
    .model{
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.8);
        position: fixed;
        z-index: 1000;
        left: 0;
        top: 0;
        @include flex();
        flex-direction: column;
        .pupop{
            width: calc(60vw - 60rpx);
            height: calc(50vw - 60rpx);
            background: #FFFFFF;
            border-radius: 16rpx;
            padding: 30rpx;
            @include flex();
            flex-direction: column;
            .title{
                font-size: 36rpx;
                height: 50rpx;
                line-height: 50rpx;
                padding: 20rpx;
                text-align: center;
            }
            .content{
                min-height: 50rpx;
                line-height: 50rpx;
                font-size: 32rpx;
                text-align: center;
                margin: auto;
            }
            .btn{
                margin-top: auto;
                padding: 20rpx;
                button{
                    font-size: 24rpx;
                    border-radius: 8rpx;
                    border: none;
                    background: #3782FF;
                    color: #FFFFFF;
                }
                button::after{
                    border: none;
                }
            }
        }
    }
</style>